package com.cn.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.cn.conn.DataManager;
import com.cn.conn.ParamSet;
import com.cn.conn.RowDatas;
import com.cn.entity.Activity_entity;


public class backstage_huodong_dao extends DataManager {
	private RowDatas<Activity_entity> activity;
	public backstage_huodong_dao() {
		activity=new Member();
	}
	//查询
	public List<Activity_entity> getactivity(){
		String sql=" SELECT * from tb_activity";
			return  queryList(sql, activity);
	}
	//修改
	public int Upactivity(int id,String title,String activity_img,String content,int activity_state,String activity_time){
		String sql="UPDATE tb_activity SET activity_img=? ,activity_state=?,activity_time=?,content=?,title=?   WHERE id=?";
		return updateExecuted(sql, new ParamSet(activity_img,activity_state,activity_time,content,title,id));
		
	}
	//添加
	public int addactivity(String title,String activity_img,String content,int activity_state,String activity_time){
		String sql="INSERT into tb_activity (activity_img,activity_state,activity_time,content,title) VALUES (?,?,?,?,?)";
		return updateExecuted(sql, new ParamSet(activity_img,activity_state,activity_time,content,title));
	}
	private class Member implements RowDatas<Activity_entity>{

		@Override
		public Activity_entity getRowData(ResultSet rs) throws SQLException {
			Activity_entity activity=new  Activity_entity();
			activity.setActivity_img(rs.getString("activity_img"));
			String activity_state;
			if(rs.getInt("activity_state")==1){
				activity_state="进行中";
			}else{
				activity_state="已结束";
			}
			activity.setActivity_state(activity_state);
			activity.setActivity_time(rs.getString("activity_time"));
			activity.setContent(rs.getString("content"));
			activity.setId(rs.getInt("id"));
			activity.setTitle(rs.getString("title"));		
			return activity;
		}
		
	}
	
}
